package cn.drh.charging.order.controller;


import cn.drh.charging.common.pojo.JsonResult;
import cn.drh.charging.order.pojo.param.OrderAddParam;
import cn.drh.charging.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName OrderController
 * @Author renhong~Deng
 * @Date 2025/5/26 14:14
 * @Version 1.0
 */


@Slf4j
@RequestMapping("/order")
@RestController
@Api(tags = "订单服务")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     *
     * @param orderAddParam 创建订单的参数
     * @return 返回创建成功与否
     */
    @ApiOperation("创建订单")
    @PostMapping("/create")
    public JsonResult createOrder(@RequestBody OrderAddParam orderAddParam) {
        log.debug("订单创建的入参-{}",orderAddParam);
        //xxx 别的代码有可能修改了入参
        //创建类型的接口是否返回结果,要根据业务来决定,如果后续的业务要基于返回的id
        //做其他的操作,比如查看详情,这个返回的id,可以作为查看订单详情的入参
        log.debug("创建订单调用service入参-{}",orderAddParam);
        String orderNo = orderService.createOrder(orderAddParam);
        log.debug("创建订单调用service入参-{},出参-{}",orderAddParam,orderNo);
        JsonResult jsonResult = JsonResult.ok(orderNo, "创建订单成功");
        log.debug("订单创建的入参-{},出参-:{}",orderAddParam,jsonResult);
        return jsonResult;
        //前端工程 if(code != 2000) {alert("订单创建成功")}
        //创建订单的出参应该是什么?
    }
}
